@extends('layouts.seller')

@section('title', '发布宝贝')

@section('content')
    <ul class="breadcrumb">
        <li class="breadcrumb-item">卖家中心</li>
        <li class="breadcrumb-item">宝贝管理</li>
        <li class="breadcrumb-item active">发布宝贝</li>
    </ul>
    <div class="content-div">
        <div class="form-div">
            <form method="post" id="Form" autocomplete="off">
                {{form_verify_field()}}
                <input type="hidden" name="newitem[catid]" value="{{$catid}}">
                <table cellspacing="0" cellpadding="0" width="100%" class="formtable">
                    <tbody>
                    <tr>
                        <td class="cell-name" width="80">类目</td>
                        <td>
                            <span>{{$catlog['name']}}</span>
                            <span style="margin-left: 10px;"><a href="{{url('seller/item/sell?itemid='.$itemid)}}" style="color: #0B90EF;">编辑类目</a></span>
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name" width="80">宝贝名称</td>
                        <td><input title="" type="text" name="newitem[title]" id="title" class="form-control w500" value="{{$item['title']}}"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">宝贝卖点</td>
                        <td>
                            <textarea title="" class="form-control w500" name="newitem[subtitle]" style="height: 60px;">{{$item['subtitle']}}</textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">一口价</td>
                        <td><input title="" type="text" name="newitem[price]" id="price" class="form-control w100" value="{{$item['price']}}"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">市场价</td>
                        <td><input title="" type="text" name="newitem[market_price]" id="price" class="form-control w100" value="{{$item['market_price']}}"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">库存数量</td>
                        <td><input title="" type="text" name="newitem[stock]" id="stock" class="form-control w100" value="{{$item['stock']}}"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">宝贝图片</td>
                        <td>第一张为宝贝主图，最后一张为海报主图，主图不能超过3MB，仅支持上传JPG格式的图片</td>
                    </tr>
                    <tr>
                        <td class="cell-name"></td>
                        <td>
                            <ul class="item-image-list" id="item-image-list">
                                @foreach($images as $img)
                                    <li>
                                        <input type="hidden" class="imgid" name="images[{{$loop->index}}][id]" value="{{$img['id']}}">
                                        <input type="hidden" class="thumb" name="images[{{$loop->index}}][thumb]" value="{{$img['thumb']}}">
                                        <input type="hidden" class="image" name="images[{{$loop->index}}][image]" value="{{$img['image']}}">
                                        <span class="iconfont icon-add"></span>
                                        <div class="bg-cover preview" style="background-image: url({{image_url($img['thumb'])}});"></div>
                                    </li>
                                @endforeach
                            </ul>
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">宝贝属性</td>
                        <td>错误填写宝贝属性，可能会引起宝贝下架或搜索流量减少，影响您的正常销售，请认真准确填写！</td>
                    </tr>
                    <tr>
                        <td class="cell-name"></td>
                        <td>
                            <div class="props" id="props">

                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">宝贝详情</td>
                        <td>
                            @include('common.editor', ['name' => 'content[content]', 'content'=>$content['content'], 'params'=>[]])
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">运费</td>
                        <td><input title="" type="text" name="newitem[shipping_fee]" id="shipping_fee" class="form-control w300" value="{{$item['shipping_fee']}}"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">上架时间</td>
                        <td>
                            <label><input type="radio" name="newitem[on_sale]" value="1"@if($item['on_sale']) checked="checked"@endif> <span>立即上架</span></label>
                            <label><input type="radio" name="newitem[on_sale]" value="0"@if(!$item['on_sale']) checked="checked"@endif> <span>存入仓库</span></label>
                        </td>
                    </tr>
                    </tbody>
                    <tfoot>
                    <tr>
                        <td width="80"></td>
                        <td><button type="submit" class="btn btn-primary">立即发布</button></td>
                    </tr>
                    </tfoot>
                </table>
            </form>
        </div>
    </div>
@stop

@section('foot')
    <script type="text/javascript">
        window.onbeforeunload = function () {
            if (confirm("你填写的信息尚未保存，是否确认要离开此页面")){

            }else {
                return false;
            }
        };
        $(function () {
            $("#item-image-list li").on('click', function () {
                var self = $(this);
                Plugins.showImagePicker(function (data) {
                    self.find('.preview').css({'background-image':'url('+data.imageurl+')'});
                    self.find('.thumb').val(data.thumb);
                    self.find('.image').val(data.image);
                });
            });

            $.ajax({
                url:'/seller/item/getprops',
                data:{catid:'{{$catid}}', itemid:'{{$itemid}}'},
                success: function (response) {
                    $("#props").html(response.table);
                }
            });

            $("#Form").on('submit', function () {
                window.onbeforeunload = null;
                var title = $.trim($("#title").val());
                if (!title) {
                    DSXUI.error('请填写宝贝名称');
                    return false;
                }

                if (title.length < 5) {
                    DSXUI.error('宝贝名称不能少于5个字');
                    return false;
                }

                var price = $.trim($("#price").val());
                if (!price) {
                    DSXUI.error('请填写产品价格');
                    return false;
                }

                if (!parseFloat(price) > 0) {
                    DSXUI.error('产品价格必须大于0');
                    return false;
                }

                var stock = $.trim($("#stock").val());
                if (!stock) {
                    DSXUI.error('请填写产品库存');
                    return false;
                }
            });
        });
    </script>
@stop
